package com.health.work.activity;

import java.util.List;

import com.health.work.R;
import com.health.work.model.normalUserBean;
import com.health.work.utils.AssistUtils;
import com.health.work.utils.HEALTHPASSPORT;
import com.health.work.utils.TipsUtil;
import com.health.work.utils.UserInfoUtils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
/**
 * 健康护照页面
 * @author star
 *
 */
public class HealthPassportActivity extends Activity{

	private TextView score;
	private Button back;
	List<normalUserBean>list;
	private String []str1={"健康档案","病例存储","健康咨询","医疗商圈"};
	private String []str2={"随时查阅自己的最新体检记录（部分省市开放）","随身携带自己的病例图片下次复查不再发愁","匿名提问，一万名医生在线解答。还可以聘请家庭医生","随时查询你周围健康商品商家，买药不再多跑冤枉路"};
	private int[]img={R.drawable.image01,R.drawable.image02,R.drawable.image03,R.drawable.image04};
	GridView grid;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.health_passport_layout);
//		String userinfo=getIntent().getStringExtra(HEALTHPASSPORT.USERINFO);
		Log.e("HealthPassportActivity", "手机号码:"+UserInfoUtils.getUserProperty(this, HEALTHPASSPORT.MOBILEPHONE));
		initPages();
	}


	private void initPages() {
		score=(TextView)findViewById(R.id.score);
		score.setText("我的健康分值："+UserInfoUtils.getUserProperty(this, HEALTHPASSPORT.INTERGRAL));
		back = (Button) findViewById(R.id.btnBack);
		back.setOnClickListener(onClickListener);
		grid=(GridView)findViewById(R.id.grid);
		grid.setAdapter(new HealthAdapter(str1, str2, img));
		grid.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				// TODO Auto-generated method stub
				Intent intent;
				switch (position) {
				case 0://健康档案
					intent=new Intent(HealthPassportActivity.this, HealthArchivesActivity.class);
					startActivity(intent);
					break;
				case 1://病例存储
					intent=new Intent(HealthPassportActivity.this, CaseStorageActivity.class);
					startActivity(intent);
					break;
				case 2://健康咨询
					intent=new Intent(HealthPassportActivity.this, HealthInquiryActivity.class);
					startActivity(intent);
					break;
				case 3://医疗商圈
					intent=new Intent(HealthPassportActivity.this, MedicalDistrictActivity.class);
					startActivity(intent);
					break;
				default:
					break;
				}
			}
		});
	}

	OnClickListener onClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.btnBack:
				TipsUtil.showExit(HealthPassportActivity.this);
				break;

			default:
				break;
			}
		}
	};

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onRestart() {
		super.onRestart();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onStart() {
		super.onStart();
	}

	@Override
	protected void onStop() {
		super.onStop();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode==KeyEvent.KEYCODE_BACK){
			TipsUtil.showExit(this);
			return true;
		}else{
			return super.onKeyDown(keyCode, event);
		}
	}
	
	private class HealthAdapter extends BaseAdapter{

		 View[] itemViews; 
		public HealthAdapter(String []str1,String []str2,int[]img){
			
			 itemViews = new View[str1.length];   
	            for (int i = 0; i < itemViews.length; i++) {           	
	                itemViews[i] = makeItemView(str1[i], str2[i],   
	                		img[i]);   
	            }

		}
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 4;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		
		
		  private View makeItemView(String strTitle, String strText, int resId) {   
	            LayoutInflater inflater = (LayoutInflater) HealthPassportActivity.this  
	                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);    
	            // 使用View的对象itemView与R.layout.item关联   
	            View itemView = inflater.inflate(R.layout.health_passport_item, null);    
	            // 通过findViewById()方法实例R.layout.item内各组件   
	            TextView title = (TextView) itemView.findViewById(R.id.text01);   
	            title.setText(strTitle);   
	            TextView text = (TextView) itemView.findViewById(R.id.text02);   
	            text.setText(strText);   
	            ImageView image = (ImageView) itemView.findViewById(R.id.image);   
	            image.setImageResource(resId);                
	            return itemView;   
	        }  
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			 if (convertView == null)   
	                return itemViews[position];   
	            return convertView;   
		}
		
	}
	
   
}
